%%%-------------------------------------------------------------------
%%% @author mirahs(2892727493@qq.com)
%%% @doc
%%%     角色数据处理
%%% @end
%%%-------------------------------------------------------------------
-module(role_parse).

-export([
    to_role/1
    ,to_role_data/1
]).

-include("common.hrl").
-include("role.hrl").
-include("role_data.hrl").


%% 将 role_data 转换成 role
to_role(#role_data{base = RoleBase, ext = RoleExt}) ->
    case role_base_parse:to_role(RoleBase) of
        {ok, Role} ->
            case role_ext_parse:to_role(Role, RoleExt) of
                {ok, Role2} -> {ok, Role2};
                {error, Reason} -> {error, Reason}
            end;
        {error, Reason} ->
            {error, Reason}
    end.

%% 将 role 转换成 role_data
to_role_data(Role = #role{rid = Rid}) ->
    {ok, RoleBase} = role_base_parse:to_role_base(Role),
    {ok, RoleExt} = role_ext_parse:to_role_ext(Role),
    {ok, #role_data{rid = Rid, base = RoleBase, ext = RoleExt}}.
